package com.douwong.student.adapter;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.View;

import com.bumptech.glide.Glide;
import com.douwong.student.R;
import com.douwong.student.contant.Config;
import com.douwong.student.model.AppInfos;
import com.douwong.student.model.Holder;
import com.douwong.student.utils.PreferencesUtils;
import com.douwong.student.utils.UIUtils;

import java.util.ArrayList;

/**
 * @autor yichao
 * @time 2016/11/2411:43
 * @des 应用
 */
public class ApplicationAdapter extends BaseAppAdapter {
    public ApplicationAdapter(ArrayList<AppInfos> onLineList, Context context) {
        super(onLineList, context);
    }

    @Override
    protected void setViewDate(Holder holder, ArrayList<AppInfos> onLineList, int position) {
        if (PreferencesUtils.getInstance().getBoolean(Config.IS_PATRIARCH,false)){
            //家长模式
            if (position==0 ){
                holder.drawb.setImageDrawable(mContext.getResources().getDrawable(R.mipmap.parent_group));
                holder.pwd_on.setVisibility(View.GONE);
            }else if (position==mOnLineList.size()-1){
                holder.drawb.setImageDrawable(mContext.getResources().getDrawable(R.mipmap.add_app));
                holder.pwd_on.setVisibility(View.GONE);

            }else {
                setCommData(holder,onLineList,position);
            }
            holder.title.setText(mOnLineList.get(position).appName);

        }else {
            //学生模式
            setCommData(holder,onLineList,position);
            holder.title.setText(mOnLineList.get(position).appName);

        }





    }

    /**
     * 设置公共的数据
     * @param holder
     * @param onLineList
     * @param position
     */
    private void setCommData(Holder holder,ArrayList<AppInfos> onLineList, int position) {
        if ( onLineList.get(position).isLocal){
            //是本地
            Drawable appIcon = UIUtils.getAppIcon(onLineList.get(position).packageName);
            holder.drawb.setImageDrawable(appIcon);
        }else {
            //线上
            if (mOnLineList.get(position).appIcoDownloadUrl != null) {
            //    ImageLoader.getInstance().displayImage(mOnLineList.get(position).appIcoDownloadUrl,holder.drawb, DisplayImageOptionsUtil.getDefaultOption());
                Glide.with(mContext).load(mOnLineList.get(position).appIcoDownloadUrl).placeholder(R.mipmap.answerdefault).into(holder.drawb);
            }

        }

        if (mOnLineList.get(position).ynControl == 1) {
            holder.pwd_on.setVisibility(View.VISIBLE);
        } else {
            holder.pwd_on.setVisibility(View.GONE);
        }
    }


}
